<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title> - 基础表格</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">

</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-6">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>住院情况</h5>

                </div>
                <div class="ibox-content">

                    <table class="table table-striped">
                        <thead>
                        <tr>
                            <th>#</th>
                            <th>科室</th>
                            <th>用户</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody id="tbody">
                        <tr>
                            <td>1</td>
                            <td>儿科</td>
                            <td>张三</td>
                            <td><a onclick="">出院</a></td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 全局js -->
<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.6"></script>


<!-- Peity -->
<script src="js/plugins/peity/jquery.peity.min.js"></script>

<!-- iCheck -->
<script src="js/plugins/iCheck/icheck.min.js"></script>

<!-- Peity -->
<script src="js/demo/peity-demo.js"></script>

<script type="application/javascript">
    // getPatient
    $(document).ready(function () {
        getPatient();
    });
    function getPatient(){
        $.ajax({
            async: false,
            type: "post",
            url: "/getPatient",
            contentType: 'application/json',
            dataType: "text",
            success: function (data) {
                var result = JSON.parse(data);
                console.log(result);
                if (result.SUCCESS) {
                    list = result.RESULT;
                    console.log(list);
                    makeList(list)
                } else {
                    console.log(result.RESULT);
                }
            },
            error: function (data) {
                alert("请求失败");
            }
        });
    }


    function makeList(list) {

        var html = "";
        for (var i = 0; i < list.length; i++) {
            /**
             *  <th>科室</th>
             <th>用户</th>
             <th>操作</th>
             * @type {string}
             */
            html += " <tr><td>" + i + "</td>";
            html += " <td>" + list[i].room + "</td>    ";
            html += " <td>" + list[i].userName + "</td>";
            html += " <td> <a onclick='outHospital(" + list[i].id + ")'>出院</a> </td>";
        }
        $('#tbody').html(html);
        console.log(html);
    }


    function outHospital(id) {
        var dto = {};
        dto["id"] = id;

        $.ajax({
            async: true,
            type: "post",
            url: "/outHospital",
            data: JSON.stringify(dto),
            contentType: 'application/json',
            dataType: "text",
            success: function (data) {
                var result = JSON.parse(data);
                console.log(result);
                if (result.SUCCESS) {
                    getPatient();
                    alert(result.RESULT);
                } else {
                    alert(result.RESULT);
                }
            },
            error: function (data) {
                alert("请求失败");
            }
        });
    }


    function getQueryData() {

        return
        dto;
    }


</script>


</body>

</html>
